(function(){
	var company_active_obj = {};

	company_active_obj.fun = {

		next:function(){
			if(!company_active_obj.config.tablewidth){
				tablelist = $(".right_one_pic table");
				company_active_obj.config.tablewidth = tablelist.eq(0).width();
			}
			right_one_pic_obj = $(this).parent().prev();
			cur = right_one_pic_obj.data("cur");
			if(!cur){
				cur = 0;
			}
			total = right_one_pic_obj.find("table").length;
			if(cur >= total - 1){
				cur = -1;
			}
			//是否还有右边的元素
			cur ++;
			innerdiv = right_one_pic_obj.find("div:eq(0)");
			tmp = - company_active_obj.config.tablewidth * cur;
			innerdiv.animate({"margin-left":tmp}, 1000);

			right_one_pic_obj.prev().find("span[num=num]").text((cur+1)+"/"+total);
			right_one_pic_obj.data("cur", cur);
			return false;
		},
		prev:function(){
			if(!company_active_obj.config.tablewidth){
				tablelist = $(".right_one_pic table");
				company_active_obj.config.tablewidth = tablelist.eq(0).width();
			}
			right_one_pic_obj = $(this).parent().prev();
			cur = right_one_pic_obj.data("cur");
			total = right_one_pic_obj.find("table").length;
			if(!cur){
				cur = total;
			}
			//是否还有右边的元素
			cur --;
			cur_table = right_one_pic_obj.find("table:eq("+ cur +")");
			innerdiv = right_one_pic_obj.find("div:eq(0)");
			tmp = - company_active_obj.config.tablewidth * cur;
			innerdiv.animate({"margin-left":tmp}, 1000);

			if(cur < 0){
				cur = total - 1;
			}
			right_one_pic_obj.prev().find("span[num=num]").text((cur+1)+"/"+total);
			right_one_pic_obj.data("cur", cur);
			return false;
		},
		del: function(){
			if(!confirm("确定删除该图片？")){
				return false;
			}
			right_one_pic_obj = $(this).parent().prev();
			cur = right_one_pic_obj.data("cur");
			if(!cur){
				cur = 0;
			}
			img_obj = right_one_pic_obj.find("img:eq("+cur+")");
			str = img_obj[0].src;
			if(!company_active_obj.config.id){
				company_active_obj.config.id = $(":input[name=id]").val();
			}

			$.getJSON('/handle.php', {"h":"admin_business_prize/delete_thumb","id":company_active_obj.config.id,"path":str}, function(data){
				if(!data.state){
					return false;
				}
				window.location = '/admin/lottery/company_active_detail?id='+company_active_obj.config.id+"&"+Math.random();
			})

		},
		del_product: function(){

			if(!confirm("确定删除该图片？")){
				return false;
			}
			right_one_pic_obj = $(this).parent().prev();
			cur = right_one_pic_obj.data("cur");
			if(!cur){
				cur = 0;
			}

			img_obj = right_one_pic_obj.find("img:eq("+cur+")");
			rel_id = img_obj.attr('rel');//获取图片的删除id
			rel_aid = img_obj.attr('rel_aid');//获取图片的删除id
			if(!company_active_obj.config.id){
				company_active_obj.config.id = $(":input[name=id]").val();
			}
			$.getJSON('/handle.php', {"h":"admin_user_album/delete_product_img","id":rel_id,'aid':rel_aid}, function(data){
				if(!data.state){

					return false;
				}
				window.location = '/admin/lottery/company_active_detail?id='+company_active_obj.config.id+"&"+Math.random();
			})

		},
		del_content_img: function(){

			if(!confirm("确定删除该图片？")){
				return false;
			}
			right_one_pic_obj = $(this).parent().prev();
			cur = right_one_pic_obj.data("cur");
			if(!cur){
				cur = 0;
			}
			img_obj = right_one_pic_obj.find("img:eq("+cur+")");
			rel_id = $(this).attr('rel');//获取图片的删除id
			rel_full_src = $(this).attr('rel_full_src');//full_src
			rel_src = img_obj.attr('rel');//src

			$.getJSON('/handle.php', {"h":"admin_community_dynamic/update_content_img","id":rel_id,'src':rel_src,'img':rel_full_src}, function(data){
				if(!data.state){
					return false;
				}
				window.location = '/admin/admin_user_dynamic_show?id='+rel_id+'&special_community=&'+Math.random();
			})

		}
	};


	company_active_obj.config = {
		tablewidth:0,
		id:0
	};

	company_active_obj.init = function(){
		$("a[next=next]").bind("click", company_active_obj.fun.next);
		$("a[prev=prev]").bind("click", company_active_obj.fun.prev);
		$("a[del=del]").bind("click", company_active_obj.fun.del);
		$("a[del=del_product]").bind("click", company_active_obj.fun.del_product);
		$("a[del=del_content_img]").bind("click", company_active_obj.fun.del_content_img);
	}



	if(window.company_active_obj == undefined){
		window.company_active_obj = company_active_obj;
	}
})();